home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1249 / remtab.t < prev    next >
Text File  |  1997-04-18  |  1KB  |  89 lines

  1. %
  2. % "remtab.t" removes tabs; see instab.t
  3. %
  4. %   Sample program for the T Interpreter by:
  5. %
  6. %   Stephen R. Schmitt
  7. %   962 Depot Road
  8. %   Boxborough, MA 01719
  9. %
  10.  
  11. const Out_file_name : string := "remtab.fil"
  12. const Tab_width : int := 8
  13.  
  14. var In_file_name: string
  15. var In_file, Out_file: int
  16. var Line: string
  17.  
  18.  
  19. program
  20.  
  21.     label program_exit :
  22.  
  23.     prompt "file to de-compress:"
  24.     get In_file_name 
  25.     
  26.     In_file := open( In_file_name, "r" )
  27.  
  28.     if In_file = 0 then
  29.  
  30.         put "cannot open file"
  31.         goto program_exit
  32.  
  33.     end if
  34.  
  35.     Out_file := open( Out_file_name, "w" )
  36.     put "Removing tabs . . . "
  37.  
  38.     loop
  39.  
  40.         exit when eof( In_file ) 
  41.         get :In_file, Line : *
  42.         put :Out_file, remove_tabs( Line )
  43.  
  44.     end loop
  45.  
  46.     if close( In_file ) = 0 or close( Out_file ) = 0 then
  47.  
  48.         put "file close error"
  49.  
  50.     end if
  51.     
  52.     put In_file_name, " -> ", Out_file_name 
  53.  
  54.     program_exit:
  55.  
  56. end program
  57.  
  58.  
  59. function remove_tabs( in: string ) : string
  60.  
  61.     var out : string
  62.     var i, j, k : int
  63.  
  64.     j := 0
  65.     for i := 0 ... length( in ) - 1 do
  66.  
  67.         if in[i] = '\t' then
  68.  
  69.             for k := 1...Tab_width do
  70.  
  71.                 out[j] := ' '
  72.                 incr j
  73.  
  74.             end for
  75.  
  76.         else
  77.  
  78.             out[j] := in[i]
  79.             incr j
  80.  
  81.         end if
  82.  
  83.     end for
  84.  
  85.     out[j] := '\0'
  86.  
  87.     return out    
  88.  
  89. end function